
************************************************************************************************************************************************
****************************** REPLICATION CODE: RELIGION AND BRAZILIAN POLITICS 
****************************** 2019. Cambridge University Press
****************************** By Amy Erica Smith (amyericas@gmail.com) 

****************************** ANALYSIS OF BEPS 2014



****************************************** VARIABLE CODING **************************************************************************************

use "C:\Users\aesmith2\Dropbox\Work\Data\BEPS 2014\Data from IDB site\BEPS_2014_v3.dta", clear

egen weight_censo2 = mean(weight_censo), by(idtelefone)
replace weight_censo = weight_censo2
drop weight_censo

**** simplify wave codings
drop if idtelefone == 59 & wave == 3 // DROP WAVE 3 FOR ONE INDIVIDUAL WHO WAS INTERVIEWED ACCIDENTALLY IN BOTH WAVES 2 AND 3
recode wave (1=1) (2 3 = 2) (4 5 = 3) (6 = 4) (7 = 5), g(newwave)
move newwave wave
xtset idtelefone newwave
g respw23 = (respw2 == 1 | respw3 == 1)
g respw45 = (respw4 == 1 | respw5 == 1)
g respw12345 = respw1 == 1 & (respw2 == 1 | respw3 == 1) & (respw4 == 1 | respw5 == 1)
g respw123456 = respw1 == 1 & (respw2 == 1 | respw3 == 1) & (respw4 == 1 | respw5 == 1) & respw6 == 1

***** STABLE VALUES OF WAVE 1 VARIABLES
foreach var in val1 val2 val2a p5 pk1 pk2 pk3 pk4 pk5 pol1 rel1 l1 {
egen `var'1 = mean(`var'), by(idtelefone)
	replace `var' = `var'1
	drop `var'1
}
************************** CODE VALUES
g care_harm = 1 if val1 == 1
	replace care_harm = .67 if val2 == 1
	replace care_harm = .33 if val2a != 1 & val2a < . & care_harm == .
	replace care_harm = 0 if val2a == 1 
g authority = 1 if val1 == 2
	replace authority = .67 if val2 == 2
	replace authority = .33 if val2a != 2 & val2a < . & authority == .
	replace authority = 0 if val2a == 2 
g equality = 1 if val1 == 3
	replace equality = .67 if val2 == 3
	replace equality = .33 if val2a != 3 & val2a < . & equality == .
	replace equality = 0 if val2a == 3
g loyalty = 1 if val1 == 4
	replace loyalty = .67 if val2 == 4
	replace loyalty = .33 if val2a != 4 & val2a < . & loyalty == .
	replace loyalty = 0 if val2a == 4
corr care_harm authority equality loyalty
g equality_inv = 1-equality
egen authorityloyalty = rmean(authority loyalty)
	summ authorityloyalty
	replace authorityloyalty = (authorityloyalty-r(min))/(r(max)-r(min))
	recode authorityloyalty (.19/.21=.2) (.39/.41=.4) (.59/.61=.6) (.79/.81=.8) 

pca care_harm authority equality loyalty
predict values
pca authority equality loyalty
predict values2


**************************** RELIGION AND EXPERIENCES IN CHURCH
g churchfreq = (5-p5)/4
	lab var churchfreq "Frequency of Church Attendance"
recode churchfreq (0/.5 = 0) (.75/1 = 1), g(churchfreq_dichot)
	
recode religion (1=1) (2/10=0), g(catholic)
	lab var catholic "Catholic"
recode religion (2 3=1) (1 4/10=0), g(evangelico)
	lab var evangelico "Evangelical/Pentecostal"
recode religion (4 5 6 7 8 10 =1) (1 2 3 9=0), g(otherreligion) //GROUPING MORMONS & JEHOVAH'S WITNESSES WITH OTHER RELIGIONS B/C SO FEW OF THEM.
	lab var otherreligion "Other Religion"
recode religion (9=1) (1/8 10=0), g(noreligion)
	lab var noreligion "No Religion"
recode religion (1=1) (2 3 = 2) (9=3) (4/8 10 = 4) , g(religion2)
	lab def religion2 1 "Catholic" 2 "Evangelical/Protestant" 3 "No Religion" 4 "Other Religion"
	lab val religion2 religion2

recode rel2 (2 .a .b .c = 0), g(pastortalkedelections)
g pastortalkedelections_w6 = 0 if wave == 6
forvalues i = 1/5 {
	recode pastortalkedelections_w6 (0 . = 1) if l`i'.pastortalkedelections == 1
}
g pastortalkedelections_w6_2 = 0 if wave == 6
forvalues i = 1/5 {
	replace pastortalkedelections_w6_2 = pastortalkedelections_w6_2+1 if l`i'.pastortalkedelections == 1
	recode pastortalkedelections_w6_2 (. = 1) if l`i'.pastortalkedelections == 1
}
replace pastortalkedelections_w6_2 = pastortalkedelections_w6_2 /3

recode rel3 (2 .a .b .c = 0), g(church_proturnout)
recode rel4 (2 .a .b .c = 0), g(church_prostudywell)
recode rel5 (2 .a .b .c = 0), g(church_cand)
	lab var church_cand "Clergy Supported Candidate"
corr church_proturnout church_prostudywell church_cand pastortalkedelections_w6_2
alpha church_proturnout church_prostudywell church_cand pastortalkedelections_w6_2, item
g churchconscience = (church_proturnout == 1 | church_prostudywell == 1) if church_proturnout < . | church_prostudywell < .

	
g church_cand_who = rel5a_1
	replace church_cand_who = 2 if rel5a_2 == 1
	replace church_cand_who = 4 if rel5a_3 == 1
	replace church_cand_who = 5 if rel5a_4 == 1
	replace church_cand_who = 6 if rel5 == 2
	lab def church_cand_who 0 "Unspecified" 1 "Dilma" 2 "Aecio" 4 "Marina" 5 "Pastor Everaldo" 6 "No Candidate"
	lab val church_cand_who church_cand_who 
g church_cand_agree = (vb1==church_cand_who) if church_cand_who < 6
	recode church_cand_agree (. = 0) if church_cand_who < 6
egen churchelections = mean(pastortalkedelections) if respw12345 == 1, by(idtelefone)
	recode churchelections (.=0) if respw12345 == 1

replace rel1 = rel1-1
egen secularism = mean(rel1), by(idtelefone)
lab var secularism "Secular Norms"	
	
**************************** CONTROLS
recode educ (1 2 = 0) (3 5 6 = 1) (4 7 8 = 2) (9 10 = 3) (11 12 13 14 = 4), g(educr)
	lab var educr "Education" 
	lab def educr 0 "No School" 1 "Primary School" 2 "Middle School" 3 "High School" 4 "Higher Education"
	lab val educr educr

nicelylabelleddummies educr, g(educr)
g educrr = educr/5
	lab var educrr "Educational Level"

replace wealth = wealth/10
	lab var wealth "Household Wealth"

egen knowledge = anycount(pk1 pk2 pk3 pk4 pk5), values(1)
replace knowledge = knowledge/5
g interest = (4-pol1)/3
g ideology = l1/10
recode ideology (0/3=1) (4/10=0), g(leftist)
g urban = 2-urb_rur
recode idade (16/25=1) (26/35=2) (36/45=3) (46/55=4) (56/65=5) (65/110=6), g(edad)
summ idade
	replace idade=(idade-r(min))/(r(max)-r(min))
lab var mulher "Woman"

*************************** partisanship 
recode vb10 (2=0), g(haspid)
	lab var haspid "Has Party Identification"

g petista = vb11==1501
	lab var petista "Petista"
g psdbista = vb11 == 1502
	lab var psdbista "Pesedebista"
g otherpartisan = haspid
	replace otherpartisan = 0 if petista == 1 | psdbista == 1
	lab var otherpartisan "Other Partisan"

egen dilma = rowmean(vb8a vb8b)
egen dilma2 = mean(dilma), by(idtelefone)
recode dilma2 (0/3 = 1) (3.1/10 = 0), g(antidilma)
recode vb15 (1501=1) (1502/1510 = 0), g(antipetista)
	recode antipetista (.a .b .c =0) if vb14 == 2
	recode antipetista (1=0) if petista == 1 
	egen ap = mean(antipetista), by(idtelefone)
	replace antipetista = ap
	drop ap
	lab var antipetista "Anti-Petista"

***** participation in civic and political groups
*dem4 = organized labor; dem5 = associations/voluntary groups; dem6 = public meetings; dem7 == party meetings
egen groups = rowmean(dem4 dem5 dem6 dem7)
		replace groups = (3-groups)/2
recode groups (.1/1=1), g(groups_dichot)
	
	
*************************** POLICY ATTITUDES
recode d6b (2=0), g(gaymarriage)
g laggaymarriage = l2.gaymarriage if newwave == 3

recode pp10 pp11 pp12 pp13 pp14 (2=0)
g ros = (pp10+pp11+pp12+pp13+pp14)/5
lab var ros "Support for Social Safety Net"

recode abort (4=3)
	replace abort = (abort-1)/2
	
replace l1 = l1/10

************************ vote choice
recode vb1 (.a .b = 14) if wave < 6
g vote_w1 = l3.vb1 if wave == 6
	recode vote_w1 (5/14=14)
	
egen candideology = mean(ideology) if wave == 6 & educr > .6 & vb1 < 13 & vb1 != 6, by(vb1)
	egen candideology2=group(candideology)
	egen candideology3=mean(candideology2) if wave == 6, by(vb1)
	summ candideology3
	replace candideology = (candideology3-r(min))/(r(max)-r(min))
	drop candideology3 candideology2

recode vb1 (13 14 .a .b = 0) (1/12=1), g(hasvote)
recode vb1 (13 14 .a .b = 1) (1/12=0), g(abstainblank)
recode vb1 (13 =.) (14 .a .b = 0) (1/12=1), g(turnout2)
		
g votesame_w16 = (vb1 == l3.vb1 & vb1<13) if respw1 == 1 & respw6 == 1 & newwave == 4
g votesame_w236 = (vb1 == l2.vb1 & vb1<13) if (respw2 == 1 | respw3 == 1) & respw6 == 1 & newwave == 4
g votesame_w456 = (vb1 == l.vb1 & vb1<13) if (respw4 == 1 | respw5 == 1) & respw6 == 1 & newwave == 4
g timetodecision = 0 if votesame_w16 == 1 & votesame_w236 == 1 & votesame_w456 == 1 & newwave == 4
	replace timetodecision = .33 if votesame_w16 == 0 & votesame_w236 == 1 & votesame_w456 == 1 & newwave == 4
	replace timetodecision = .67 if votesame_w16 == 0 & votesame_w236 == 0 & votesame_w456 == 1 & newwave == 4
	replace timetodecision = .67 if votesame_w16 == 1 & votesame_w236 == 0 & votesame_w456 == 1 & newwave == 4
	replace timetodecision = 1 if votesame_w16 == 0 & votesame_w236 == 0 & votesame_w456 == 0 & newwave == 4
	replace timetodecision = 1 if votesame_w16 == 1 & votesame_w236 == 0 & votesame_w456 == 0 & newwave == 4
	replace timetodecision = 1 if votesame_w16 == 0 & votesame_w236 == 1 & votesame_w456 == 0 & newwave == 4
	replace timetodecision = 1 if votesame_w16 == 1 & votesame_w236 == 1 & votesame_w456 == 0 & newwave == 4
	replace timetodecision = . if vb1>12 & newwave == 4

	
*********************** god in control and climate
recode climex 2=0
recode climexpb 2=0, g(godincontrol)	
recode clim3 clim4 (1=2) (2=1) (3=0)
g droughteffect = (4-clim1)/3
recode clim2 (1/8=0) (9=1), g(droughtfromgod)

************ INTER-GROUP ATTITUDES
* grup1: PT
* grup2: PSDB
* grup3: Catholics
* grup4: Evangelicals
* grup5: Atheists
forvalues i = 1/5 {
	replace grup`i' = grup`i'/10
}
egen maxtherm = rowmax(grup3 grup4 grup5)
egen mintherm = rowmin(grup3 grup4 grup5)
g polarization_relig = maxtherm-mintherm
g polarization_pols = abs(grup1-grup2)

g pt_v_psdb = grup1-grup2



************************************************************************************************************************************************
************************************************************************************************************************************************
****************************************** ANALYSIS ********************************************************************************************


******************** FIGURE 8.3. INTER-GROUP RELATIONS
preserve
collapse grup* (semean) se1=grup1 se2=grup2 se3=grup3 se4=grup4 se5=grup5, by(religion2)
	drop if religion2 >= . 
	lab def religion2 1 "Catholic Respondents" 2 "Evangelical Respondents" 3 "Nonreligious Respondents" 4 "Other Religion", modify
	lab val religion2 religion2
forvalues group =1/5 {
	g lb`group' = grup`group'-2*se`group'
	g ub`group' = grup`group'+2*se`group'
}
reshape long grup se lb ub, i(religion2) j(group)
rename grup estimate
lab def group 1 "PT" 2 "PSDB" 3 "Catholics" 4 "Evangelicals" 5 "Atheists", modify
lab val group group
graph twoway (rspike lb ub group, horizontal lcolor(gs10)) ///
			(scatter group estimate if group == 1, mcolor(black) msymbol(D)) ///
			(scatter group estimate if group == 2, mcolor(gs12) msize(medlarge) msymbol(D)) ///
			(scatter group estimate if group == 3, mcolor(black) msymbol(O)) ///
			(scatter group estimate if group == 4, mcolor(gs12) msize(medlarge) msymbol(O)) ///
			(scatter group estimate if group == 5, mcolor(black) msize(large) msymbol(X)), ///
	by(religion2, col(1) imargin(zero) ///
		note("Source: Brazilian Electoral Panel Study 2014." "Whiskers represent 95% confidence intervals.", span) ///
		graphregion(fcolor(white) lcolor(black))  ) ///
	subtitle(, pos(7) ring(0) nobexpand fcolor(gs15) lcolor(gs10)) ///
	ysize(6) ytitle("") ylabel(none)  ///
	legend(subtitle("Level of Approval of:", size(small)) order(6 "Atheists" 5 "Evangelicals" 4 "Catholics" 3 "PSDB" 2 "PT") col(3) size(small)) ///
	xlabel(0(.25)1, grid) yline(5.5, lcolor(gs10) lwidth(thin))
restore
******************** END FIGURE 8.3. INTER-GROUP RELATIONS
